using System.Collections.Generic;
using UnityEngine;

public class IngameUI : GameUI
{
	public Game game;

	public GameObject panelPregame;

	public GameObject panelInplay;

	public GameObject panelPostGame;

	public GameObject panelHowToPlay;

	public GameObject panelSelectWeapon;

	public GameObject x2CoinButton;

	public UILabel lbMapName;

	public UILabel lbWaveName;

	public UILabel lbTime;

	public UICenterOnChild center;

	public Transform[] guideObjects;

	public UIScrollView scrView;

	public UIGrid grid;

	public SelectWeaponPrefab selectWeaponPrefab;

	public UILabel lbKill;

	public UILabel lbHeadShot;

	public UILabel lbWaves;

	public UILabel lbTotalScore;

	public UILabel lbCoin;

	private int currentCoinEarned;

	[SerializeField]
	private List<SelectWeaponPrefab> currentListing;

	public UISprite[] sprHealthBar;

	public UILabel[] lbName;

	public UILabel[] lbPowerUpCount;

	public UIGrid gridPowerUps;

	public UISprite sprSound;

	public UISprite sprMusic;

	public UILabel lbSound;

	public UILabel lbMusic;

	public GameObject pausePanel;

	public void ShowPlayingInfo(string mapName, int waveCount)
	{
		lbMapName.text = mapName;
		lbWaveName.text = "Wave " + waveCount;
	}

	public void ShowPreGame()
	{
		panelPregame.SetActive(value: true);
		panelInplay.SetActive(value: false);
		panelPostGame.SetActive(value: false);
		ShowHowToPlay();
	}

	public void ShowInplay()
	{
		panelPregame.SetActive(value: false);
		panelInplay.SetActive(value: true);
		panelPostGame.SetActive(value: false);
	}

	public void ShowPostGame()
	{
		panelPregame.SetActive(value: false);
		panelInplay.SetActive(value: false);
		panelPostGame.SetActive(value: true);
		ShowGameStats(game.playerController.info);
	}

	private void ShowGameStats(CharacterInformation info)
	{
		int num = info.kills * 100 + info.headShots * 10 + info.waves * 500;
		currentCoinEarned = Mathf.RoundToInt((float)num / 3f);
		lbKill.text = info.kills + string.Empty;
		lbHeadShot.text = info.headShots + string.Empty;
		lbWaves.text = info.waves + string.Empty;
		lbTotalScore.text = num + string.Empty;
		lbCoin.text = currentCoinEarned + string.Empty;
		PersistenData.Coin += currentCoinEarned;
		// x2CoinButton.SetActive(currentCoinEarned > 0);
	}

	public void x2Coin()
	{
		x2CoinButton.SetActive(value: false);
	}

	public void StartPlayGame()
	{
		game.TouchToStartGame();
		ClearList();
	}

	public void RateNow()
	{
		Application.OpenURL("https://play.google.com/store/apps/details?id=com.skyapps.stickmanlegendsofsurvival");
	}

	public void ToMenu()
	{
		game.ResumeGame();
		game.LoadMenu(start: false);
	}

	public void Replay()
	{
		game.ResumeGame();
		game.StartNewGame();
	}

	public void ShowTime(string time, float duration = 0.5f)
	{
		lbTime.text = time;
		lbTime.GetComponent<TweenAlpha>().duration = duration;
		lbTime.GetComponent<TweenScale>().ResetToBeginning();
		lbTime.GetComponent<TweenScale>().PlayForward();
		lbTime.GetComponent<TweenAlpha>().ResetToBeginning();
		lbTime.GetComponent<TweenAlpha>().PlayForward();
	}

	public void NextGuide()
	{
		int num = 0;
		for (int i = 0; i < guideObjects.Length; i++)
		{
			if (guideObjects[i].gameObject == center.centeredObject)
			{
				num = i + 1;
				if (num >= guideObjects.Length)
				{
					num = 0;
				}
				break;
			}
		}
		center.CenterOn(guideObjects[num]);
	}

	public void PrevGuide()
	{
		int num = 0;
		for (int i = 0; i < guideObjects.Length; i++)
		{
			if (guideObjects[i].gameObject == center.centeredObject)
			{
				num = i - 1;
				if (num < 0)
				{
					num = guideObjects.Length - 1;
				}
				break;
			}
		}
		center.CenterOn(guideObjects[num]);
	}

	public void ShowHowToPlay()
	{
		panelHowToPlay.SetActive(value: true);
		panelSelectWeapon.SetActive(value: false);
	}

	public void ShowSelectWeapon()
	{
		panelHowToPlay.SetActive(value: false);
		bool flag = LoadOwnedWeaponList();
		panelSelectWeapon.SetActive(flag);
		if (!flag)
		{
			StartPlayGame();
		}
	}

	private bool LoadOwnedWeaponList()
	{
		bool flag = false;
		Weapon[] weaponPool = game.weaponPool;
		foreach (Weapon weapon in weaponPool)
		{
			if (PersistenData.checkHasItem(weapon.PrefKey))
			{
				flag = true;
				break;
			}
		}
		if (flag)
		{
			if (currentListing == null)
			{
				currentListing = new List<SelectWeaponPrefab>();
			}
			SelectWeaponPrefab selectWeaponPrefab = Object.Instantiate(this.selectWeaponPrefab, grid.transform);
			selectWeaponPrefab.SetItem(null, this);
			currentListing.Add(selectWeaponPrefab);
			Weapon[] weaponPool2 = game.weaponPool;
			foreach (Weapon weapon2 in weaponPool2)
			{
				if (PersistenData.checkHasItem(weapon2.PrefKey))
				{
					SelectWeaponPrefab selectWeaponPrefab2 = Object.Instantiate(this.selectWeaponPrefab, grid.transform);
					selectWeaponPrefab2.SetItem(weapon2, this);
					currentListing.Add(selectWeaponPrefab2);
				}
			}
			Invoke("ResetPositionList", 0.05f);
		}
		return flag;
	}

	private void ClearList()
	{
		if (currentListing != null)
		{
			foreach (SelectWeaponPrefab item in currentListing)
			{
				if (item != null && item.gameObject != null)
				{
					UnityEngine.Object.Destroy(item.gameObject);
				}
			}
		}
		currentListing.Clear();
	}

	private void ResetPositionList()
	{
		scrView.ResetPosition();
		grid.Reposition();
	}

	public void UseWeapon(int weaponID)
	{
		PersistenData.UseWeapon(weaponID);
		foreach (SelectWeaponPrefab item in currentListing)
		{
			item.ShowUsing();
		}
	}

	public void ShowPowerUpCount()
	{
		if (PersistenData.HealPowerUps == 0)
		{
			lbPowerUpCount[0].transform.parent.gameObject.SetActive(value: false);
		}
		else
		{
			lbPowerUpCount[0].text = PersistenData.HealPowerUps + string.Empty;
		}
		if (PersistenData.ImmoPowerUps == 0)
		{
			lbPowerUpCount[1].transform.parent.gameObject.SetActive(value: false);
		}
		else
		{
			lbPowerUpCount[1].text = PersistenData.ImmoPowerUps + string.Empty;
		}
		if (PersistenData.FreezePowerUps == 0)
		{
			lbPowerUpCount[2].transform.parent.gameObject.SetActive(value: false);
		}
		else
		{
			lbPowerUpCount[2].text = PersistenData.FreezePowerUps + string.Empty;
		}
		gridPowerUps.Reposition();
	}

	public void ShowPausePanel()
	{
		if (PersistenData.Sound)
		{
			sprSound.color = new Color32(38, 147, 40, byte.MaxValue);
			lbSound.text = "On";
		}
		else
		{
			sprSound.color = Color.grey;
			lbSound.text = "Off";
		}
		if (PersistenData.Music)
		{
			sprMusic.color = new Color32(38, 147, 40, byte.MaxValue);
			lbMusic.text = "On";
		}
		else
		{
			sprMusic.color = Color.grey;
			lbMusic.text = "Off";
		}
		pausePanel.SetActive(value: true);
	}

	public void HidePausePanel()
	{
		pausePanel.SetActive(value: false);
	}
}
